# 线程

"""
考虑: 创建线程? 如何使用线程

线程状态:
1.新建  start-> 2.就绪 等待CPU调用-> 3.运行 4.阻塞(阻塞发生后会到就绪状态) 5.结束
就绪状态的线程争夺CPU资源
"""
import threading
from time import sleep


# 进程: Process
# 线程: Thread

def download(n):
    images = ['girl.jpg', 'boy.jpg', 'man.jpg']
    for image in images:
        print('正在下载: ', image)
        sleep(n)
        print('下载{}成功'.format(image))


def listenMusic():
    musics = ['简单爱', '一眼万年', 'The One']
    for music in musics:
        sleep(0.5)
        print('正在听{}歌'.format(music))

if __name__ == '__main__':

    # 线程对象
    t1 = threading.Thread(target=download, name='aa', args=(1,))
    t1.start()
    t2 = threading.Thread(target=listenMusic, name='aa')
    t2.start()

    n = 1
    while True:
        print(n)
        sleep(1.5)
        n += 1
